package cn.com.dcsgo.controller;

import cn.com.dcsgo.domain.Order;
import cn.com.dcsgo.dto.OrderQueryDTO;
import cn.com.dcsgo.dto.PageDTO;
import cn.com.dcsgo.model.Result;
import cn.com.dcsgo.service.OrderService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 后台管理订单相关接口
 *
 * @author Dcsgo
 * @since 2025/11/16 16:04
 */
@Tag(name = "后台管理订单相关接口")
@RestController
@RequestMapping("order/order")
public class ManagerOrderController {
    @Resource
    private OrderService orderService;

    @GetMapping("page")
    @PreAuthorize("hasAuthority('order:order:page')")
    @Operation(summary = "分页获取订单数据")
    public Result<Page<Order>> getOrderPage(PageDTO pageDTO, OrderQueryDTO orderQueryDTO) {
        return Result.success(orderService.getOrderPage(pageDTO, orderQueryDTO));
    }

    @GetMapping("orderInfo/{orderNumber}")
    @PreAuthorize("hasAuthority('order:order:info')")
    @Operation(summary = "获取订单数据")
    public Result<Order> getOrder(@PathVariable String orderNumber) {
        // TODO 使用VO返回数据，包含order、orderItems（价格计算）、买家信息、收货信息
        return Result.success(orderService.getByOrderNumber(orderNumber));
    }
}
